package com.example.questionnaire.controller;

import java.util.Arrays;
import java.util.Map;

import com.example.questionnaire.dto.AnswerUserDto;
import com.example.questionnaire.dto.QuestionnaireAddDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.questionnaire.entity.ProblemEntity;
import com.example.questionnaire.service.ProblemService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;



/**
 * 
 *
 * @author hsz
 * @email 1416446590@qq.com
 * @date 2022-11-01 22:59:47
 */
@CrossOrigin
@RestController
@RequestMapping("questionnaire/problem")
public class ProblemController {
    @Autowired
    private ProblemService problemService;

    /**
     * 列表
     */
    @ApiOperation("展示题库列表,正常分页，展示类，不支持查询")
    @ApiImplicitParam(name = "params",value = "params(page、limit、userId题目属于谁的)")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = problemService.queryPage(params);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @ApiOperation("展示问题全部东西")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		ProblemEntity problem = problemService.getById(id);
        return R.ok().put("data", problem);
    }

    /**
     * 保存
     */
    @ApiOperation("导入单个问题")
    @PostMapping("/save")
    public R save(@RequestBody ProblemEntity problemEntity){
		problemService.save(problemEntity);
        return R.ok();
    }
    /**
     * 修改
     */
    @ApiOperation("修改问题")
    @PostMapping("/update")
    public R update(@RequestBody ProblemEntity problem){
		problemService.updateById(problem);
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除问题，ids是问题id数组，支持批量删除")
    @PostMapping("/delete")
    public R delete(@RequestBody AnswerUserDto answerUserDto){
		problemService.removeByIds(Arrays.asList(answerUserDto.getIds()));
        return R.ok();
    }

    /**
     * 批量导入问题
     */
    @ApiOperation("批量导入问题,问题数组")
    @PostMapping("/savebatch")
    public R savebatch(@RequestBody ProblemEntity[] problem){
        problemService.saveBatch(Arrays.asList(problem));
        return R.ok();
    }

}
